#!/usr/bin/env python

from _octodb import *

# Transaction isolation
DIRTY_READ      = 0
READ_COMMITTED  = 1
REPEATABLE_READ = 2
SERIALIZED      = 3

if __name__ == '__main__':
	db = OctoDBDatabase('/home/isteve/svn/octodb/tests/benchmarks/data/base')

	db.open()

#	table = OctoDBTable('table1')
#	table.add_column(OctoDBColumn('pkey', 'int64'))
#	table.add_column(OctoDBColumn('data', 'string'))
#	db.table_create(table)
#
	table = OctoDBTable('table2')
	table.add_column(OctoDBColumn('pkey', 'int64'))
	table.add_column(OctoDBColumn('data', 'array', 'int64'))
	db.table_create(table)
#
#	db.table_drop('table2')

	transaction = OctoDBTransaction(db, READ_COMMITTED)

	query = OctoDBQuerySelect(transaction, 'table2')
#	query.add_conditions(OctoDBConditionPredicate(1, 'ge', 'Ab'), OctoDBConditionPredicate(1, 'lt', 'Abg'))
#	query.add_conditions(OctoDBConditionPredicate(0, 'lt', 10000))
	query.execute()
	for item in query:
		print item[0], item[1]
	query.finalize()

	query = OctoDBQueryInsert(transaction, 'table2')
	query.execute()
	query.set_data('1000', [123, 456, 789])
#	query.set_data('1000', 'asd')
	query.step()
	query.finalize()
	
#	query = OctoDBQueryDelete(transaction, 'table1')
#	query.execute()
#	query.finalize()

#	def callback(query, row):
#		if row[0] != 1000:
#			return True
#		else:
#			return False
#	query.add_conditions(OctoDBConditionCallback(callback))

	query = OctoDBQuerySelect(transaction, 'table2')
	query.execute()
	for item in query:
		print item[0], item[1]
	query.finalize()

	transaction.commit()
	db.close()
